<?php
class Template
{
    private $layoutDir;

    public function __construct()
    {
        global $ENV;
        $this->layoutDir = $ENV['root'] . '/app/view/layout/';
    }
    public function render($vars, $file)
    {
        global $ENV;
        if (!is_array($vars) && $vars !== null)
            return;
        if ($vars)
            foreach ($vars as $n => $v)
                if (is_string($n))
                    $this->$n = $v;
        if (is_file($file))
            include $file;
    }
    
    public function __get($name)
    {
        debug('Template: get undefined properity <strong>' . $name . '</strong>');
        return '';
    }

    public function layout($name)
    {
        $file = $this->layoutDir . $name . '.tpl.php';
        if (is_file($file))
            include $file;
        else
            debug('Template: layout ' . $name . ' not exist.');

    }
}
?>
